Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class StringArr
	
	Private mstrArray() As String
	Private mlngCount As Integer
	Private mlngIncrement As Integer
	
	'UPGRADE_NOTE: Class_Initialize was upgraded to Class_Initialize_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	Private Sub Class_Initialize_Renamed()
		Clear()
	End Sub
	Public Sub New()
		MyBase.New()
		Class_Initialize_Renamed()
	End Sub
	
	Public Sub Clear()
		ReDim mstrArray(4) 'start with 5 elements
		mlngCount = 0
		mlngIncrement = 5
	End Sub
	
	
	Public Property Item(ByVal ZeroBasedIndex As Integer) As String
		Get
			If ZeroBasedIndex < 0 Or ZeroBasedIndex >= mlngCount Then
				Err.Raise(1, "Item(" & CStr(ZeroBasedIndex) & ")", "Item index out of range")
			End If
			Item = mstrArray(ZeroBasedIndex)
		End Get
		Set(ByVal Value As String)
			If ZeroBasedIndex < 0 Or ZeroBasedIndex >= mlngCount Then
				Err.Raise(1, "Item(" & CStr(ZeroBasedIndex) & ")", "Item index out of range")
			End If
			mstrArray(ZeroBasedIndex) = Value
		End Set
	End Property
	
	Public ReadOnly Property Count() As Integer
		Get
			Count = mlngCount
		End Get
	End Property
	Public Property zAutoIncrementUnits() As Integer
		Get
			zAutoIncrementUnits = mlngIncrement
		End Get
		Set(ByVal Value As Integer)
			If mlngIncrement >= 1 Then
				mlngIncrement = Value
			End If
		End Set
	End Property
	
	
	Public Property zArraySize() As Integer
		Get
			zArraySize = UBound(mstrArray) + 1
		End Get
		Set(ByVal Value As Integer)
			If Value > UBound(mstrArray) + 1 Then
				ReDim Preserve mstrArray(Value - 1)
			End If
		End Set
	End Property
	
	Public Sub Add(ByRef NewItem As String)
		If Not RoomAvailable Then
			AddRoom()
		End If
		mstrArray(mlngCount) = NewItem
		mlngCount = mlngCount + 1
	End Sub
	
	Private Function RoomAvailable() As Boolean
		If mlngCount < UBound(mstrArray) Then
			RoomAvailable = True
		Else
			RoomAvailable = False
		End If
	End Function
	
	Private Sub AddRoom()
		ReDim Preserve mstrArray(UBound(mstrArray) + mlngIncrement)
	End Sub
	
	'UPGRADE_NOTE: InputString was upgraded to InputString_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	Public Sub GenerateNewFromString(ByVal InputString_Renamed As String, ByVal ParseCharacter As String, Optional ByRef SuperTrimEachElement As Boolean = True, Optional ByRef AddBlankElements As Boolean = True, Optional ByRef StripQuoteChar As String = "")
		

		Dim strTemp As String
		Dim aryInputString() As String
		Dim lngIndex As Integer
		If InStr(1, InputString_Renamed, ParseCharacter, CompareMethod.Binary) = 0 Then
			'No parse character means no "array"...ss
			'RESET THE ARRAY TO 1 ELEMENT
			ReDim mstrArray(0)
			mlngCount = 0
			If Len(StripQuoteChar) > 0 Then
				If Left(InputString_Renamed, Len(StripQuoteChar)) = StripQuoteChar And Right(InputString_Renamed, Len(StripQuoteChar)) = StripQuoteChar Then
					InputString_Renamed = Mid(InputString_Renamed, Len(StripQuoteChar) + 1, Len(InputString_Renamed) - (Len(StripQuoteChar) * 2))
				End If
			End If
			If AddBlankElements = True Then
				Add(InputString_Renamed)
			Else
				If Len(InputString_Renamed) > 0 Then
					Add(InputString_Renamed)
				End If
			End If
		Else
			'OK... we're going to have an array.
			aryInputString = Split(InputString_Renamed, ParseCharacter)
			
			'RESET ARRAY AND PRESIZE TO FIT ENTIRE ARRAY
			ReDim mstrArray(UBound(aryInputString))
			mlngCount = 0
			
			For lngIndex = 0 To UBound(aryInputString)
				strTemp = aryInputString(lngIndex)
				If SuperTrimEachElement = True Then
					strTemp = MyTrim(strTemp)
				End If
				If Len(StripQuoteChar) > 0 Then
					If Left(strTemp, Len(StripQuoteChar)) = StripQuoteChar And Right(strTemp, Len(StripQuoteChar)) = StripQuoteChar Then
						strTemp = Mid(strTemp, Len(StripQuoteChar) + 1, Len(strTemp) - (Len(StripQuoteChar) * 2))
					End If
				End If
				If AddBlankElements = True Then
					Add(strTemp)
				Else
					If Len(strTemp) > 0 Then
						Add(strTemp)
					End If
				End If
			Next 
		End If
	End Sub
	
	Public Function Glue(Optional ByVal GlueChars As String = ",", Optional ByVal QuoteChars As String = "", Optional ByVal StartIndex As Integer = 0, Optional ByVal MaxCount As Integer = 0) As Object
		
		If MaxCount < 1 Then
			MaxCount = mlngCount
		End If
		
		If (StartIndex + MaxCount) > mlngCount - 1 Then
			MaxCount = mlngCount - StartIndex
		End If
		
        Dim strTemp As String = ""
		Dim lngIndex As Integer
		
		For lngIndex = StartIndex To StartIndex + MaxCount - 1
			If lngIndex = StartIndex + MaxCount - 1 Then
				'last one
				strTemp = strTemp & QuoteChars & mstrArray(lngIndex) & QuoteChars
			Else
				strTemp = strTemp & QuoteChars & mstrArray(lngIndex) & QuoteChars & GlueChars
			End If
		Next 
		
		'UPGRADE_WARNING: Couldn't resolve default property of object Glue. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Glue = strTemp
		
		If InStr(1, VB.Command(), "DEBUG", CompareMethod.Text) > 0 Then
			'UPGRADE_WARNING: Couldn't resolve default property of object Glue. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			MsgBox("Glue: " & Glue) ''DEBUG ONLY
		End If
		
	End Function
	
	Sub EliminateDuplicates()
		
		Dim objNewArray As StringArr
		Dim lngIndex As Integer
		objNewArray = New StringArr
		
		'read items into new array
		For lngIndex = 0 To mlngCount - 1
			If objNewArray.IndexOf(mstrArray(lngIndex)) = -1 Then
				objNewArray.Add(mstrArray(lngIndex))
			End If
		Next 
		
		'copy them back in to the current array
		If objNewArray.Count > 0 Then
			ReDim mstrArray(objNewArray.Count - 1)
		Else
			ReDim mstrArray(0)
		End If
		
		For lngIndex = 0 To objNewArray.Count - 1
			mstrArray(lngIndex) = objNewArray.Item(lngIndex)
		Next 
		
		mlngCount = objNewArray.Count
		
	End Sub
	
	Public Function Exists(ByRef LookFor As String) As Boolean
		Exists = (IndexOf(LookFor) > -1)
	End Function
	
	Public Function IndexOf(ByRef LookFor As String, Optional ByRef StartIndex As Integer = 0) As Integer
		
		IndexOf = -1 'Default
		
		Dim lngIndex As Integer
		For lngIndex = StartIndex To mlngCount - 1
			If StrComp(mstrArray(lngIndex), LookFor, CompareMethod.Text) = 0 Then
				IndexOf = lngIndex
				Exit Function
			End If
		Next 
	End Function
	
	Public Function Last() As String
		If mlngCount > 0 Then
			Last = mstrArray(mlngCount - 1)
		Else
			Last = ""
		End If
	End Function
End Class